//
//  LGCancerPatientDetailHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/9.
//

#import "LGCancerPatientDetailHeader.h"

@interface LGCancerPatientDetailHeader()

/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *vipView;
/**   */
@property (nonatomic , strong)UIButton *doctorBtn;
/**   */
@property (nonatomic , strong)UILabel *phoneLabel;
/**   */
@property (nonatomic , strong)NSDictionary *vipWidth;

@end

@implementation LGCancerPatientDetailHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.vipWidth = @{@"1":@(16),@"2":@(32),@"3":@(48),@"4":@(64)};
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    //姓名、VIP、主治医生
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    
    //性别、年龄
    NSString *gender = LGNSString(dataDic[@"gender"]);
    NSString *age = LGNSString(dataDic[@"age"]);
    
    if(gender.length>0 && age.length >0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",gender,age];
    }else if (gender.length > 0 && age.length == 0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@",gender];
    }else if (gender.length == 0 && age.length>0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@岁",age];
    }else{
        self.ageLabel.text = @"";
    }
    
    NSString *vipLevel = LGNSString(dataDic[@"vip_level"]);
    self.vipView.image = [UIImage imageNamed:[NSString stringWithFormat:@"vip_icon_%@",vipLevel]];
    CGFloat vipWidth = [self.vipWidth.allKeys containsObject:vipLevel]?[self.vipWidth[vipLevel] floatValue]:0;
    [self.vipView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(vipWidth));
    }];
    CGFloat left = ([vipLevel integerValue] > 0)?(viewPix(12)+vipWidth):viewPix(6);
    NSString *doctorName = LGNSString(dataDic[@"doctor_name"]);
    CGFloat width = [doctorName textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT];
    width = (doctorName.length>0)?width+viewPix(35):0;
    [self.doctorBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(left);
        make.width.equalTo(@(width));
    }];
    [self.doctorBtn setTitle:doctorName forState:UIControlStateNormal];
    self.doctorBtn.hidden = (doctorName.length>0)?NO:YES;
    
    //手机号、用户ID
    NSString *phone = LGNSString(dataDic[@"mobile"]);
    NSString *number = LGNSString(dataDic[@"hospital_bano"]);
    if (phone.length>0 && number.length>0) {
        self.phoneLabel.text = [NSString stringWithFormat:@"手机号 %@    用户ID %@",phone,number];
    }else if (phone.length>0 && number.length == 0){
        self.phoneLabel.text = [NSString stringWithFormat:@"手机号 %@",phone];
    }else if (phone.length==0 && number.length > 0){
        self.phoneLabel.text = [NSString stringWithFormat:@"用户ID %@",number];
    }else{
        self.phoneLabel.text = @"";
    }
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.vipView];
    [self.baseView addSubview:self.doctorBtn];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.phoneLabel];
    [self.baseView addSubview:self.consultBtn];
    [self.baseView addSubview:self.phoneBtn];
    [self.baseView addSubview:self.historyBtn];

    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(15));
    }];
    
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(4));
        make.centerY.equalTo(self.nameLabel);
    }];
    
    [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(16));
        make.height.equalTo(@(16));
    }];
    
    [self.doctorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(viewPix(70)));
        make.height.equalTo(@(viewPix(22)));
    }];

    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(12));
    }];
    
    [self.consultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.bottom.equalTo(self.baseView);
        make.width.equalTo(@((Screen_W-viewPix(56))/3));
        make.height.equalTo(@(viewPix(48)));
    }];
    
    [self.phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.consultBtn.mas_right);
        make.centerY.width.height.equalTo(self.consultBtn);
    }];
    
    [self.historyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.phoneBtn.mas_right);
        make.centerY.width.height.equalTo(self.consultBtn);
    }];
}

-(UIImageView *)baseView{
    if(!_baseView){
        _baseView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"患者档案-个人信息"]];
        _baseView.frame = CGRectMake(viewPix(16), viewPix(8), Screen_W-viewPix(32), viewPix(112));
        _baseView.userInteractionEnabled = YES;
    }
    return _baseView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"姓名" colorString:@"#FFFFFF" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UIImageView *)vipView{
    if(!_vipView){
        _vipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    }
    return _vipView;
}

-(UIButton *)doctorBtn{
    if(!_doctorBtn){
        _doctorBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(12, UIFontWeightMedium) textColor:@"#56BEA0" imageName:@"药球患者-医生"];
        _doctorBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _doctorBtn.imageEdgeInsets = UIEdgeInsetsMake(0, viewPix(10), 0, 0);
        _doctorBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(12), 0, 0);
        _doctorBtn.backgroundColor = [UIColor colorWithString:@"#EBF8F3"];
        _doctorBtn.userInteractionEnabled = NO;
        _doctorBtn.cornerRidus = viewPix(11);
    }
    return _doctorBtn;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UILabel *)phoneLabel{
    if(!_phoneLabel){
        _phoneLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _phoneLabel;
}

-(UIButton *)consultBtn{
    if(!_consultBtn){
        _consultBtn = [UIButton buttonWithImage:@"患者档案-团队咨询" selectImage:@"患者档案-团队咨询"];
        [_consultBtn setImage:[UIImage imageNamed:@"患者档案-团队咨询"] forState:UIControlStateHighlighted];
    }
    return _consultBtn;
}


-(UIButton *)phoneBtn{
    if(!_phoneBtn){
        _phoneBtn = [UIButton buttonWithImage:@"患者档案-电话随访" selectImage:@"患者档案-电话随访"];
        [_phoneBtn setImage:[UIImage imageNamed:@"患者档案-电话随访"] forState:UIControlStateHighlighted];
    }
    return _phoneBtn;
}

-(UIButton *)historyBtn{
    if(!_historyBtn){
        _historyBtn = [UIButton buttonWithImage:@"患者档案-病史信息" selectImage:@"患者档案-病史信息"];
        [_historyBtn setImage:[UIImage imageNamed:@"患者档案-病史信息"] forState:UIControlStateHighlighted];
    }
    return _historyBtn;
}

@end
